package com.example.a79273.shandianban.model;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * "有人"页面上的viewpager的数据接口对应的javabean
 */
public class YouRenIndexBean {

    /**
     * error_code : 0
     * error_msg : 获取广告成功
     * total : 4
     * data : {"bannerlist":[{"pic_id":"","pic_scr":"/Upload/Banner/372e51e69a.jpg","pic_url":"","pic_text":"-1"},{"pic_id":"237000774091","pic_scr":"/Upload/Banner/372e8eef47.jpg","pic_url":"237000774091","pic_text":"0"},{"pic_id":"/Topic/240000760071","pic_scr":"/Upload/Banner/37e1477e34.jpg","pic_url":"/Topic/240000760071","pic_text":"5"},{"pic_id":"214000520032","pic_scr":"/Upload/Banner/37e1477e5d.jpg","pic_url":"214000520032","pic_text":"0"}]}
     */

    private int error_code;
    private String error_msg;
    private int total;
    private DataBean data;

    public static YouRenIndexBean objectFromData(String str) {

        return new Gson().fromJson(str, YouRenIndexBean.class);
    }

    public static YouRenIndexBean objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getString(str), YouRenIndexBean.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<YouRenIndexBean> arrayYouRenIndexBeanFromData(String str) {

        Type listType = new TypeToken<ArrayList<YouRenIndexBean>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<YouRenIndexBean> arrayYouRenIndexBeanFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<YouRenIndexBean>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getString(str), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }

    public int getError_code() {
        return error_code;
    }

    public void setError_code(int error_code) {
        this.error_code = error_code;
    }

    public String getError_msg() {
        return error_msg;
    }

    public void setError_msg(String error_msg) {
        this.error_msg = error_msg;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public static class DataBean {
        /**
         * pic_id :
         * pic_scr : /Upload/Banner/372e51e69a.jpg
         * pic_url :
         * pic_text : -1
         */

        private List<BannerlistBean> bannerlist;

        public static DataBean objectFromData(String str) {

            return new Gson().fromJson(str, DataBean.class);
        }

        public static DataBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getString(str), DataBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<DataBean> arrayDataBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<DataBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<DataBean> arrayDataBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<DataBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getString(str), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public List<BannerlistBean> getBannerlist() {
            return bannerlist;
        }

        public void setBannerlist(List<BannerlistBean> bannerlist) {
            this.bannerlist = bannerlist;
        }

        public static class BannerlistBean {
            private String pic_id;
            private String pic_scr;
            private String pic_url;
            private String pic_text;

            public static BannerlistBean objectFromData(String str) {

                return new Gson().fromJson(str, BannerlistBean.class);
            }

            public static BannerlistBean objectFromData(String str, String key) {

                try {
                    JSONObject jsonObject = new JSONObject(str);

                    return new Gson().fromJson(jsonObject.getString(str), BannerlistBean.class);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return null;
            }

            public static List<BannerlistBean> arrayBannerlistBeanFromData(String str) {

                Type listType = new TypeToken<ArrayList<BannerlistBean>>() {
                }.getType();

                return new Gson().fromJson(str, listType);
            }

            public static List<BannerlistBean> arrayBannerlistBeanFromData(String str, String key) {

                try {
                    JSONObject jsonObject = new JSONObject(str);
                    Type listType = new TypeToken<ArrayList<BannerlistBean>>() {
                    }.getType();

                    return new Gson().fromJson(jsonObject.getString(str), listType);

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return new ArrayList();


            }

            public String getPic_id() {
                return pic_id;
            }

            public void setPic_id(String pic_id) {
                this.pic_id = pic_id;
            }

            public String getPic_scr() {
                return pic_scr;
            }

            public void setPic_scr(String pic_scr) {
                this.pic_scr = pic_scr;
            }

            public String getPic_url() {
                return pic_url;
            }

            public void setPic_url(String pic_url) {
                this.pic_url = pic_url;
            }

            public String getPic_text() {
                return pic_text;
            }

            public void setPic_text(String pic_text) {
                this.pic_text = pic_text;
            }
        }
    }
}
